<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">

<link href="css/redmond/jquery-ui-1.10.3.custom.min.css" rel="stylesheet" type="text/css">	<!-- jquery UI CSS函式庫 -->
<link href="css/selfTemplate.css" rel="stylesheet" type="text/css">							<!-- 自建CSS函式庫 -->

<script src="js/jquery-1.10.2.min.js" type="text/javascript"></script>								<!-- jquery 函式庫 -->
<script src="js/jquery-ui-1.10.3.custom.js" type="text/javascript"></script>					<!-- jquery UI 函式庫 -->
<script src="js/jquery.cookie.js" type="text/javascript"></script>								<!-- 操做cookie用 -->
<script src="js/widgets.js" type="text/javascript"></script>									<!-- 自建函式庫 -->

<script type="text/javascript">


/** 進入待辦事項 **/
function getInside(obj) {
	var itemType = $(obj).attr("itemType");
	var masterId = $(obj).attr("masterId");
	var jobName = "";
	var jobSN = "";
	if( itemType == "3" || itemType == "4" ) {
		jobName = masterId.split( TOKENONE )[0];
		jobSN = masterId.split( TOKENONE )[1];
		masterId=0;
	} else if ( itemType == "2" ) {	//申請繳交程式，因為其內容過多，會導致cookie爆錶，故至下一個頁面再查詢
		$.cookie("actType", "review");	//目前頁面將如何動作
		$.cookie("chkInId", masterId );
		$.cookie("toDoListId", $(obj).attr("toDoListId"));	//待辦事項ID
		window.location="chkIn.html";
	}
	
	$.ajax({	//取得待辦事項清單
		type : 'post',
		url : 'IsComplete',
		dataType : 'text',
		async:false,
		data: {itemType:itemType,masterId:masterId,jobName:jobName,jobSN:jobSN},
		success : function(reses) {
			if ( itemType=="1" ) {//變更申請
				$.cookie("actType", "review");	//目前頁面將如何動作
				$.cookie("modUnit", reses);		//模組的資訊
				$.cookie("craId", masterId );	//變更申請單號
				$.cookie("toDoListId", $(obj).attr("toDoListId"));	//待辦事項ID
				window.location="modUnit.html";
			} else if ( itemType=="3" ) {	//等待安排部署時間
				$.cookie("toDoListId", $(obj).attr("toDoListId"));	//待辦事項ID
				$.cookie("testDep", reses);	 //部署的相關資訊
				window.location="testerDep.html";
			} else if ( itemType=="4" ) {	//回覆測試結果
				$.cookie("toDoListId", $(obj).attr("toDoListId"));	//待辦事項ID
				$.cookie("testDep", reses);	 //部署的相關資訊
				$.cookie("itemType", itemType);	 //供前端分辨是  等待安排部署時間? 還是 部署的相關資訊?
				window.location="testerDep.html";
			} else if ( itemType=="5" ) {//申請變更模組
				$.cookie("actType", "review");	//目前頁面將如何動作
				$.cookie("craId", masterId );	//變更申請單號
				$.cookie("cra", reses);
				$.cookie("toDoListId", $(obj).attr("toDoListId"));	//待辦事項ID
				window.location="creCra.html";
			} else if ( itemType=="6" ) {//申請定義模組相依性
				$.cookie("actType", "review");	//目前頁面將如何動作
				$.cookie("defModBEseq", reses);		//相依性的申請資訊
				$.cookie("craId", masterId );	//變更申請單號
				$.cookie("toDoListId", $(obj).attr("toDoListId"));	//待辦事項ID
				window.location="defModBEseq.html";
			}
			
		}, error : function(xhr, ajaxOptions, thrownError) { errorAjx(xhr); }
	});
}

$(document).ready(function(){
	init("doDoList.html");
	
	$.ajax({	//取得待辦事項清單
		type : 'post',
		url : 'GenToDoList',
		dataType : 'json',
		async:false,
		data: {empId:$.cookie("empId")},
		success : function(reses) {
			if (reses.length !=0) {
				errorMsgShow("");
				tmp = "<thead class='tableFirst'><tr><th>&nbsp;</th><th>#</th><th>子系統</th><th>提交人員</th><th>提出日期</th><th>類型</th></tr></thead><tbody id='tbodyToDoList'></tbody>";
				$("#tableToDoList").append(tmp);
			
				$.each(reses, function(i,res){
					tmp ="<tr><td class='center'><button type='button'"+ 
						" masterId='"+res.s5+"'" +		//主檔ID
						" itemType='"+res.i2+"'" +		//是做什麼動作
						" toDoListId='"+res.i1+"'" +	//todolist ID 動作完要移除
						" onclick=getInside(this)>進入</button></td><td class='idx'>"+(i+1)+"</td><td>"+res.s4+"</td><td>"+res.s3+"</td><td class='dt'>"+res.s2+"</td><td>"+res.s1+"</td></tr>";
					$("#tbodyToDoList").append(tmp);
				});
				refreshUI(1,"tbodyToDoList",false);
			} else {
				errorMsgShow("恭喜~ 目前沒有待處理的事");
			}
		}, error : function(xhr, ajaxOptions, thrownError) { errorAjx(xhr); }
	});
	
	$("button").button();
});

</script>

</head>
<body>

<div id="header"></div>

<table id="tableToDoList"></table>

</body>
</html>